<center><b><?php echo $listobj->listname; ?></b></center>
<form id="editlistmembers" method="post" action="">
<div style="text-align:center;">

<input type="hidden" name="previoussearch" value="<?php p($previoussearch) ?>" />
<input type="hidden" name="userid" value="<?php p($userid) ?>" />
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
<input type="hidden" name="contextid" value="<?php p($contextid) ?>" />
<input type="hidden" name="listid" value="<?php p($listid) ?>" />
  <table summary="" style="margin-left:auto;margin-right:auto" border="0" cellpadding="5" cellspacing="0">
    <tr>
      <td valign="top">
          <label for="removeselect"><?php print_string('listmembers', 'block_email_list', $numlistmembers); ?></label>
          <br />
          <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
                  onfocus="getElementById('editlistmembers').add.disabled=true;
                           getElementById('editlistmembers').remove.disabled=false;
                           getElementById('editlistmembers').addselect.selectedIndex=-1;">

          <?php
            $i = 0;
            $hidden="";

            if ( !empty($numlistmembers) ) {

                foreach ($listmembers as $listmember) {
                    // if (!$listmember->userid == 0 && $listmember->extaddr) ...
                    $user = $DB->get_record('user', array('id' => $listmember->userid));

                    if (empty($user)) { // possibly delete non-referenced users
                        continue;
                    }
                    $fullname = user_displayname($user, $hascapfullname);
                    //}
                    echo "<option value=\"$listmember->userid\">".$fullname."</option>\n";
                    $i++;
                }
            }

            if ($i==0) {
                echo '<option/>'; // empty select breaks xhtml strict
            }
          ?>

          </select></td>
      <td valign="center">
        <br />
        <p class="arrow_button">
            <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
            <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
        </p>
      </td>
      <td valign="top">
          <label for="addselect"><?php print_string('potentialusers', 'role', $usercount); ?></label>
          <br />
          <select name="addselect[]" size="20" id="addselect" multiple="multiple"
                  onfocus="getElementById('editlistmembers').add.disabled=false;
                           getElementById('editlistmembers').remove.disabled=true;
                           getElementById('editlistmembers').removeselect.selectedIndex=-1;">
          <?php
            $i=0;
            if (!empty($searchtext)) {
                echo "<optgroup label=\"".get_string('searchresults')." (" . $usercount . ")\">\n";

                if (!empty($usercount)) {

                    foreach ($availableusers as $user) {
                        $fullname = user_displayname($user, $hascapfullname);
                        echo "<option value=\"$user->id\">".$fullname."</option>\n";
                        $i++;
                    }
                }
                echo "</optgroup>\n";

            } else {

                if ($usercount > MAX_USERS_PER_PAGE) {
                    echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
                          .'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
                } else {

                    if ( !empty($usercount) ) {

                        foreach ($availableusers as $user) {
                            $fullname = user_displayname($user, $hascapfullname);
                            echo "<option value=\"$user->id\">".$fullname."</option>\n";
                            $i++;
                        }
                    }
                }
            }

            if ($i==0) {
                echo '<option/>'; // empty select breaks xhtml strict
            }
          ?>
         </select>
         <br />
         <label for="searchtext" class="accesshide"><?php p(get_string('search')) ?></label>
         <input type="text" name="searchtext" id="searchtext" size="30" value="<?php p($searchtext, true) ?>"
                  onfocus ="getElementById('editlistmembers').add.disabled=true;
                            getElementById('editlistmembers').remove.disabled=true;
                            getElementById('editlistmembers').removeselect.selectedIndex=-1;
                            getElementById('editlistmembers').addselect.selectedIndex=-1;"
                  onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
                               if (keyCode == 13) {
                                    getElementById('editlistmembers').previoussearch.value=1;
                                    getElementById('editlistmembers').submit();
                               } " />
         <input name="search" id="search" type="submit" value="<?php p(get_string('search')) ?>" />
         <?php
              if (!empty($searchtext)) {
                  echo '<input name="showall" id="showall" type="submit" value="'.get_string('showall').'" />'."\n";
              }
         ?>
       </td>
    </tr>
  </table>
</div>
</form>